home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / vmware-tools / resume-vm-default < prev    next >
Encoding:
Text File  |  2010-12-19  |  3.8 KB  |  146 lines

  1. #!/bin/sh
  2. ##########################################################
  3. # Copyright (C) 2001-2008 VMware, Inc. All rights reserved.
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU Lesser General Public License as published
  7. # by the Free Software Foundation version 2.1 and no later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. # or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
  12. # License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public License
  15. # along with this program; if not, write to the Free Software Foundation, Inc.,
  16. # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
  17. #
  18. ##########################################################
  19.  
  20. ##########################################################################
  21. # DO NOT modify this file directly as it will be overwritten the next
  22. # time the VMware Tools are installed.
  23. ##########################################################################
  24.  
  25. echo `date` ": Executing '$0'"
  26. echo
  27.  
  28. find_networking_script() {
  29.     local script="error"
  30.     for dir in "/etc/init.d" "/sbin/init.d" "/etc" "/etc/rc.d" ; do
  31.         if [ -d "$dir/rc0.d" ] &&
  32.         [ -d "$dir/rc1.d" ] &&
  33.         [ -d "$dir/rc2.d" ] &&
  34.         [ -d "$dir/rc3.d" ] &&
  35.         [ -d "$dir/rc4.d" ] &&
  36.         [ -d "$dir/rc5.d" ] &&
  37.         [ -d "$dir/rc6.d" ]; then
  38.  
  39.         # Now find the appropriate networking script.
  40.         if [ -d "$dir/init.d" ]; then
  41.         if [ -x "$dir/init.d/network" ]; then
  42.             script="$dir/init.d/network"
  43.         elif [ -x "$dir/init.d/networking" ]; then
  44.             script="$dir/init.d/networking"
  45.         fi
  46.         else
  47.         if [ -x "$dir/network" ]; then
  48.             script="$dir/network"
  49.         elif [ -x "$dir/networking" ]; then
  50.             script="$dir/networking"
  51.         fi
  52.         fi
  53.         fi
  54.     done
  55.  
  56.     echo "$script"
  57. }
  58.  
  59. rescue_NIC() {
  60.    niclist="/var/run/vmware-active-nics"
  61.  
  62.    ifup_path=`which ifup 2>/dev/null`;
  63.    if [ $? -ne 0 ]; then
  64.       return 1;
  65.    fi
  66.  
  67.    ifconfig_path=`which ifconfig 2>/dev/null`;
  68.    if [ $? -ne 0 ]; then
  69.       return 1;
  70.    fi
  71.  
  72.    if [ -f "$niclist" ]; then
  73.       while read nic; do
  74.          if $ifconfig_path $nic | egrep '^ +UP ' >/dev/null 2>&1; then
  75.             echo `date` "[resume-vm-default::rescue_nic] $nic is already active."
  76.          else
  77.             echo `date` "[rescue_nic] activating $nic ..."
  78.  
  79.             $ifup_path $nic
  80.          fi
  81.       done < $niclist
  82.  
  83.       rm -f $niclist
  84.    fi
  85. }
  86.  
  87.  
  88. #
  89. # wakeNetworkManager --
  90. #
  91. #    Wake the NetworkManager daemon (maybe).
  92. #
  93. #    See http://projects.gnome.org/NetworkManager/developers/spec.html .
  94. #
  95. # Results:
  96. #    Sleep(false)request is sent to the NetworkManager D-Bus interface.
  97. #
  98. # Side effects:
  99. #    None.
  100. #
  101.  
  102. wakeNetworkManager() {
  103.    # `which' may be a bit noisy, so we'll shush it.
  104.    dbusSend=`which dbus-send 2>/dev/null`
  105.    if [ $? -eq 0 ]; then
  106.       # NetworkManager 0.6
  107.       $dbusSend --system --dest=org.freedesktop.NetworkManager          \
  108.          /org/freedesktop/NetworkManager                                \
  109.          org.freedesktop.NetworkManager.wake
  110.       # NetworkManager 0.7.0
  111.       $dbusSend --system --dest=org.freedesktop.NetworkManager          \
  112.          /org/freedesktop/NetworkManager                                \
  113.          org.freedesktop.NetworkManager.Sleep boolean:false
  114.    fi
  115. }
  116.  
  117.  
  118. #
  119. # main
  120. #
  121.  
  122. wakeNetworkManager
  123.  
  124. network=`find_networking_script`
  125. if [ "$network" != "error" ]; then
  126.    "$network" restart
  127.    # Continue even if the networking init script wasn't successful.
  128.    status=0
  129. else
  130.    echo "networking script not found"
  131.    status=1
  132. fi
  133.  
  134. if [ $status -eq 0 ]; then
  135.     rescue_NIC
  136. fi
  137.  
  138. scriptsdir="`dirname $0`/scripts/`basename $0`.d"
  139. if [ -d "$scriptsdir" ]; then
  140.     for scriptfile in "$scriptsdir"/*; do
  141.     [ -x "$scriptfile" ] && "$scriptfile" resume-vm
  142.     done
  143. fi
  144.  
  145. exit "$status"
  146.